<?php
namespace app\admin\validate;
use think\Validate;

class Content extends Validate
{
    protected $rule = [
        'type' => 'require|number',
        'category_id' => 'requireCallback:check_require|number',
        'member_id' => 'requireCallback:check_require|number|gt:0',
        'location' => 'requireCallback:check_require',
        'content' => 'require'
    ];

    protected $message = [
        'type.require' => '内容类型不能为空',
        'type.number' => '内容类型错误',
        'category_id.requireCallback' => '请选择分类',
        'category_id.number' => '分类错误',
        'member_id.requireCallback' => '会员ID不能为空',
        'member_id.number' => '会员ID只能是数字',
        'member_id.gt' => '会员ID不能是0',
        'location.requireCallback' => '地点不能为空',
        'content.require' => '内容不能为空',
    ];

    function check_require($value, $data) {
        if ($data['type'] > 0) {
            return true;
        }
        return false;
    }
}